const routes = [{
		path: '/',
		name: 'layout',
        redirect: '/index', 
		component: 'layout',
		children: [
			{
			meta: {title: '首页'},
			component: 'index/index',
			},
			{
			meta: {title: '商品管理'},
			component: 'shop/goods/list',
			},
			 {
			meta: {title: '商品分类'},
			component: 'shop/category/style',
			}, 
			{
			meta: {title: '相册管理'},
			component: 'image/index',
			},
			{
			meta: {title: '分类列表'},
			component: 'shop/category/list',
			}		
		 ]
	},
	{
		meta: {
			title: '登录'
		},
		component: 'login/index'
	},/* {
		path: '*',
		redirect:{name:'index'}, 
	} */
]
let getRoutes = function() {
	createRoute(routes)
	return routes
}

function createRoute(arr) {
	for (let i = 0; i < arr.length; i++) {
		if (!arr[i].component) return
		let val = getValue(arr[i].component)
		arr[i].name = arr[i].name || val.replace(/\//g, '/')
		arr[i].path = arr[i].path || `/${val}`
		let componentFun = import(`../../views/${arr[i].component}.vue`)
		arr[i].component = () => componentFun
		if (arr[i].children && arr[i].children.length > 0) {
			createRoute(arr[i].children)
		}
	}
}
/* str = login/index */
function getValue(str) {
	let index = str.lastIndexOf('/')
	let val = str.substring(index + 1, str.length)
	if (val === 'index') {
		return str.substring(index, 0)
	}
	return str
}
export default getRoutes()
